Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

putil-defineconst

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

putil-defineconst

Helper function for defining const properties easily

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

putil-defineconst

NPM Version NPM Downloads Build Status Test Coverage Dependencies DevDependencies

Helper function for defining & configuring consts and properties easily

Installation

$ npm install putil-defineconst --save

Usage

defineConst([target], name, value, [enumerable=true])

  • targe [Object] Target object
  • name [String] Property name
  • value [*] Property value
  • enumerable ['Boolean'] Enumerable flag
const defineConst = require('putil-defineconst');
const a = {};
defineConst(a, 'prm1', 123);
a.prm1 = 1234;
assert.equal(a.prm1, 123);
assert.equal(a.propertyIsEnumerable('prm1'), true);

defineConst([target], name, value, [config])

  • targe [Object] Target object
  • name [String] Property name
  • value [*] Property value
  • config ['Object'] Configuration object
const defineConst = require('putil-defineconst');
const a = {};
defineConst(a, 'prm1', 123, {writable: false, enumerable: false});
a.prm1 = 1234;
assert.equal(a.prm1, 123);
assert.equal(a.propertyIsEnumerable('prm1'), false);

defineConst([target], properties, [enumerable=true])

  • targe [Object] Target object
  • name [Object] Key/value pair object that includes properties to be defined
  • enumerable ['Boolean'] Enumerable flag
const a = {};
defineConst(a, {
  prm1: 123,
  prm2: 'abc'
});
a.prm1 = 1234;
a.prm2 = 'aaa';
assert.equal(a.prm1, 123);
assert.equal(a.propertyIsEnumerable('prm1'), true);
assert.equal(a.prm2, 'abc');
assert.equal(a.propertyIsEnumerable('prm2'), true);

defineConst([target], properties, [config])

  • targe [Object] Target object
  • name [Object] Key/value pair object that includes properties to be defined
  • config ['Object'] Configuration object
const a = {};
defineConst(a, {
  prm1: 123,
  prm2: 'abc'
}, {
  writable: false,
  enumerable: true
});
a.prm1 = 1234;
a.prm2 = 'aaa';
assert.equal(a.prm1, 123);
assert.equal(a.propertyIsEnumerable('prm1'), true);
assert.equal(a.prm2, 'abc');
assert.equal(a.propertyIsEnumerable('prm2'), true);

Node Compatibility

  • node >= 4.0;

License

MIT

Keywords

FAQs

Package last updated on 18 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc